package com.ht.module.info.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.CollectionUtils;
import com.ht.module.info.service.IInfoOrderService;
import com.ht.util.*;
import com.ht.module.info.entity.InfoOrder;

import javax.validation.Valid;
import java.util.*;


/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Auto-generator
 * @since 2021-12-03
 */
@Api(tags = "订单表 ")
@RestController
@RequestMapping("/info-order")
public class InfoOrderController {

    
    @Autowired
    private IInfoOrderService iInfoOrderService;


    /**
     * 修改状态
     * @return
     */
    @PostMapping("/updateState/{id}/{val}")
    public JsonResult updateState(@PathVariable String id, @PathVariable String val){
        iInfoOrderService.updateState(id,val);
        return JsonResult.success();
    }


    @ApiOperation(value = "商户订单查询")
    @GetMapping("/findPageByMerchants")
    public JsonResult findPageByMerchants(Pager<InfoOrder> pager, InfoOrder infoOrder){
        return JsonResult.success(iInfoOrderService.findPageByMerchants(pager,infoOrder));
    }


    @ApiOperation(value = "分页查询")
    @GetMapping("/findPageByMe")
    public JsonResult findPageByMe(Pager<InfoOrder> pager, InfoOrder infoOrder){
        return JsonResult.success(iInfoOrderService.findPageByMe(pager,infoOrder));
    }


    /**
     * 通过id查询
     */
    @GetMapping("/get-by-id/{id}")
    @ApiOperation(value = "通过id查询")
    public JsonResult getById(@PathVariable(value = "id") String id){
        return JsonResult.success(iInfoOrderService.findById(id));
    }



    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public JsonResult add(@RequestBody @Valid InfoOrder infoOrder){
        iInfoOrderService.add(infoOrder);
        return JsonResult.success();
    }


    @DeleteMapping("/delete-by-id/{id}")
    @ApiOperation(value = "删除")
    public JsonResult delete(@PathVariable(value = "id") String id){
        iInfoOrderService.removeById(id);
        return JsonResult.success();
    }


}
